<?
/*
in: listguest=id1|row||id2|row||&ms=id1|ms1||id2|ms2||
out:(*_*)gues1||id||status||text1$$text2(*_*)gues2||id||status||text(*_*)
*/

$listguest= isset($_POST['listguest']) ? $_POST['listguest'] : array();
$ms= isset($_POST['ms']) ? $_POST['ms'] : "";
$length= isset($_POST['length']) ? $_POST['length'] : 0;
$idban= isset($_POST['idban']) ? $_POST['idban'] : "-1";
$typing= isset($_POST['typing']) ? $_POST['typing'] : 0;
$idnow= isset($_POST['idnow']) ? $_POST['idnow'] : 0;

if($idban>0)
{
	$dbsql->query("delete from ".$GLOBALS['first_table']."tblchat where iChatId=$idban");
}

//insert ms:
$ms=explode("||",$ms);
for($i=0;$i<count($ms);$i++)
{
	$r_ms_arr=explode("|",$ms[$i]);
	$roomId=$r_ms_arr[0];
	$msg=$r_ms_arr[1];
	if($roomId<=0)continue;
	if(!empty($msg))
	{
		$sql_update="update ".$GLOBALS['first_table']."tblchat set 
					cText=concat(cText,'".$username."++".$msg."$$'),
					cUserTyping='0(*_*)"._TIME."'
					where iChatId=$roomId";
		$dbsql->query($sql_update);
	}	
}

//update typing:
if($idnow>0)
{
	$sql_update="update ".$GLOBALS['first_table']."tblchat set 
			cUserTyping='".$typing."(*_*)"._TIME."'
			where iChatId='$idnow'";
	$dbsql->query($sql_update);
}

//load ms:
for($u=0;$u<5;$u++)
{
	$data=LoadMsOfUser();
	if($length==0 || (strlen($data)!=$length && strlen($text)>0))break;
	//usleep(500000);
	break;
}
echo $data;


exit();
?>